import pygame
from settings import *

class Hero(pygame.sprite.Sprite):
    def __init__(self):
        super().__init__()

        self.image = pygame.image.load(FILE_PATH + "image/me1.png").convert_alpha()
        self.image2 = pygame.image.load(FILE_PATH + "image/me2.png").convert_alpha()
        self.destroy_images = []
        self.destroy_images.extend([
            pygame.image.load(FILE_PATH + "image/me_destroy_1.png").convert_alpha(),
            pygame.image.load(FILE_PATH + "image/me_destroy_2.png").convert_alpha(),
            pygame.image.load(FILE_PATH + "image/me_destroy_3.png").convert_alpha(),
            pygame.image.load(FILE_PATH + "image/me_destroy_4.png").convert_alpha()
        ])
        self.rect = self.image.get_rect()
        self.rect.centerx = SCREEN_RECT.centerx
        self.rect.bottom = SCREEN_RECT.bottom - 60
        self.speed = 10
        self.active = True
        self.invincible = False
        self.mask = pygame.mask.from_surface(self.image)
    def moveUp(self):
        if self.rect.top > 0:
            self.rect.top -= self.speed
        else:
            self.rect.top = 0
    def moveDown(self):
        if self.rect.bottom < SCREEN_RECT.height - 60:
            self.rect.top += self.speed
        else:
            self.rect.bottom = SCREEN_RECT.height - 60
    def moveLeft(self):
        if self.rect.left > 0:
            self.rect.left -= self.speed
        else:
            self.rect.left = 0
    def moveRight(self):
        if self.rect.right < SCREEN_RECT.width:
            self.rect.right += self.speed
        else:
            self.rect.right = SCREEN_RECT.width
    def reset(self):
        self.active = True
        self.invincible = True
        self.rect.centerx = SCREEN_RECT.centerx
        self.rect.bottom = SCREEN_RECT.bottom - 60
